package com.cslc.wechat.test;


import java.lang.reflect.Method;

import junit.framework.TestCase;

import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class BaseTestCase extends TestCase {

	protected static ApplicationContext applicationContext;
	
	protected void setUp() throws Exception {
		PropertyConfigurator.configure("conf/log4j.properties");
		if (applicationContext == null) {
			applicationContext = new FileSystemXmlApplicationContext(
					"classpath:spring/applicationContext.xml");
		}
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	protected Object privateMethodInvoke(Object testInstance, String methodName,
			Class[] paramClass, Object[] paramValue) throws Exception {
		Object result = null;
		try {
			Method m = testInstance.getClass().getDeclaredMethod(methodName,
					paramClass);
			m.setAccessible(true);
			result = m.invoke(testInstance, paramValue);
			m.setAccessible(false);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return result;
	}
}
